package adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.administrator.newxlmedical.R;

import java.util.List;

import beans.LogDetailBean;
import butterknife.BindView;
import custom.BaseRecyclerAdapter;

/**
 * Created by Administrator on 2018/5/9.
 */

public class LogDetailAdapter extends BaseRecyclerAdapter<LogDetailAdapter.LogDetailViewHolder> {

    private Context mContext;
    private LayoutInflater inflater;
    private List<LogDetailBean> list;
    private OnClickListener onClickListener;

    public LogDetailAdapter(Context mContext, List<LogDetailBean> list) {
        this.mContext = mContext;
        this.list = list;
        inflater=LayoutInflater.from(mContext);
    }


    @Override
    public LogDetailViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        LogDetailViewHolder viewHolder = new LogDetailViewHolder(inflater.inflate(R.layout.adapter_log_detail, parent, false));
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(final LogDetailViewHolder viewHolder, final int position) {
        LogDetailBean logDetailBean = list.get(position);
        viewHolder.tvGoodsName.setText(logDetailBean.getGoodsName());
        viewHolder.tvSpecification.setText(logDetailBean.getSpecification());
        viewHolder.tvSupplier.setText(logDetailBean.getSupplier());
        viewHolder.tvNumber.setText(logDetailBean.getNumber());
        viewHolder.tvUnit.setText(logDetailBean.getUnit());
        if (position % 2 == 0) {
            viewHolder.linearLayout.setBackgroundColor(mContext.getResources().getColor(R.color.partLineBackground));
        } else {
            viewHolder.linearLayout.setBackgroundColor(mContext.getResources().getColor(R.color.white));
        }

    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class LogDetailViewHolder extends BaseRecyclerAdapter.BaseViewHolder {
        @BindView(R.id.tv_adapter_log_detail_goods_name)
        TextView tvGoodsName;
        @BindView(R.id.tv_adapter_log_detail_specification)
        TextView tvSpecification;
        @BindView(R.id.tv_adapter_log_detail_supplier)
        TextView tvSupplier;
        @BindView(R.id.tv_adapter_log_detail_number)
        TextView tvNumber;
        @BindView(R.id.tv_adapter_log_detail_unit)
        TextView tvUnit;
        @BindView(R.id.ll_adapter_log_detail_title)
        LinearLayout linearLayout;

        public LogDetailViewHolder(View itemView) {
            super(itemView);
        }
    }

    public void setOnClickListener(OnClickListener onClickListener) {
        this.onClickListener = onClickListener;
    }

    public interface OnClickListener {
        //        void onShowDetailSpecification(int position, TextView view);
        void onShowDetail(int position, TextView view,int xOffWidth);
        //        void onShowDetailSupplier(int position, TextView view);
    }
}
